document.querySelector('#btn-login').addEventListener('click',async function(){
    const data = serialize(document.querySelector('.login-form'),{hash:true,empty:true})
    // console.log(data)
    const {username,password}=data
    if(username==''||password=='')return showToast('用户名和密码不能为空')
    try{
        const res =await axios.post('/login',data)
        console.log(res)
        showToast(res.message)
        localStorage.setItem('username',res.data.username)
        localStorage.setItem('token',res.data.token)

        setTimeout(() => {
        location.href='./index.html'
    }, 1500);
        }catch(error){
         console.dir(error) 
        showToast(error.reponse.data.message)  
        }

})